const express=require('express')
const cors=require('cors')
const multer=require('multer')
const uuid=require('uuid')

const app=express()
app.listen(9000,()=>{
    console.log('9000端口上传服务器启动了');
})
app.use(cors())
app.use(express.static('upload'))

const upload=multer({
    storage:multer.diskStorage({
        destination:'upload',
        filename:(req,file,callback)=>{
            let fn=file.originalname
            let ext=fn.substring(fn.lastIndexOf('.'))
            callback(null,uuid.v4()+ext)
        }
    })
})

app.post('/upload',upload.single('avatar'),(req,res)=>{
    res.send(req.file)
})






